package cn.org.alexander.entity.response;

import cn.org.alexander.constant.ResultConstant;

import java.io.Serializable;

/**
 * @author Alexander
 * @date 2022/5/21
 * @desc
 */
public class ResponseResult implements Serializable {


    private static final long serialVersionUID = 4948748411472209506L;
    private boolean success = ResultConstant.SUCCESS;
    private String code = ResultConstant.SUCCESS_CODE;
    private String msg = ResultConstant.SUCCESS_MSG;


    public ResponseResult(ResultCode resultCode) {
        this.code=resultCode.code();
        this.msg=resultCode.msg();
        this.success=resultCode.success();
    }

    public ResponseResult(boolean success, String code, String msg) {
        this.success = success;
        this.code = code;
        this.msg = msg;
    }

    public ResponseResult(String msg) {
        this.msg = msg;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }


    public static ResponseResult SUCCESS(){
        return new ResponseResult(CommonCode.SUCCESS);
    }

    public static ResponseResult SERVER_ERROR(){
        return new ResponseResult(CommonCode.SERVER_ERROR);
    }

    public static ResponseResult newErrorInstance(String errMsg){
        return new ResponseResult(false,"B99998",errMsg);
    }
}